Micron Document
πŸŽ–οΈGitΠ―Ρ€Π°πŸŽ–οΈ


Displaying Rendered β€’ View raw β€’ Download

specs/20260511-211823-compose-screenshot-testing/quickstart.md docs/obtainium-generated-deeplinks (42f311dd) Text, 4.18 KB

Quickstart: Adding Screenshot Tests

Feature: 018-compose-screenshot-testing

This guide explains how to add a new preview composable and wire it into the screenshot test suite.

Prerequisites

β€’ JDK 21, T383838ANDROID_HOME set, proto submodule initialized
β€’ T383838android.experimental.enableScreenshotTest=true in T383838gradle.properties

Step 1: Create a Preview Composable

Add a T383838@Preview or T383838@PreviewLightDark composable in your module's T383838commonMain:

T282828
T8b949e// feature/messaging/src/commonMain/kotlin/.../component/MyComponentPreviews.kt

Tf0883e@PreviewLightDark
Tf0883e@Composable
Tff7b72fun Td2a8ffMyComponentPreviewTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3AppTheme Tb4b4b4{
Te6edf3MyComponentTb4b4b4(
Te6edf3title Tff7b72= Ta5d6ff"Ta5d6ffSample TitleTa5d6ff"Tb4b4b4,
Te6edf3subtitle Tff7b72= Ta5d6ff"Ta5d6ffSample subtitle textTa5d6ff"Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}


Rules:
β€’ Visibility: public (no modifier) β€” the screenshot-tests module must import it across module boundaries (T383838internal does NOT work across modules)
β€’ Theme: Always wrap in T383838AppTheme { ... }
β€’ Data: Use hardcoded synthetic values β€” never real user data or PII
β€’ Dependencies: No ViewModel, DI, or network access β€” stateless only
β€’ Determinism: Avoid time-dependent or random data (e.g., T383838Channel.getRandomKey(), relative timestamps like "last heard X ago") β€” these cause flaky diffs

Step 2: Add a Screenshot Test Wrapper

Create or update a file in the screenshot-tests module:

T282828
T8b949e// screenshot-tests/src/screenshotTest/kotlin/org/meshtastic/screenshots/feature/MessagingScreenshotTests.kt

Tf0883e@PreviewTest
Tf0883e@PreviewLightDark
Tf0883e@Composable
Tff7b72fun Td2a8ffMyComponentScreenshotTestTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3MyComponentPreviewTb4b4b4(Tb4b4b4)
Tb4b4b4}


Rules:
β€’ Must have T383838@PreviewTest annotation (from T383838com.android.tools.screenshot)
β€’ Must also have the same T383838@Preview or T383838@PreviewLightDark as the source preview
β€’ Function can be T383838public (default) β€” this is a test, not API surface

Step 3: Generate Reference Images

T282828
./gradlew :screenshot-tests:updateDebugScreenshotTest

Reference images are saved to T383838screenshot-tests/src/screenshotTestDebug/reference/.

Step 4: Validate

T282828
./gradlew :screenshot-tests:validateDebugScreenshotTest

If no UI changes were made, this passes. If the rendered output differs from references, it fails and produces an HTML diff report at T383838screenshot-tests/build/reports/screenshotTest/preview/debug/index.html.

Step 5: Commit Reference Images

T282828
git add screenshot-tests/src/screenshotTestDebug/reference/
git commit -m Ta5d6ff"Add screenshot references for MyComponent"


Reference images must be in version control so CI can validate against them.

Updating After UI Changes

If you intentionally change a component's appearance:

1. Run the update task to regenerate references:
T282828
./gradlew :screenshot-tests:updateDebugScreenshotTest
2. Review the updated PNGs in T383838screenshot-tests/src/screenshotTestDebug/reference/
3. Commit the updated images
4. Validate:
T282828
./gradlew :screenshot-tests:validateDebugScreenshotTest

Common Issues

Preview not found by CST: Ensure the preview function is public (no modifier, not T383838private or T383838internal) and the T383838screenshot-tests module has an T383838implementation(project(":your:module")) dependency.

Theme not applied: Wrap preview content in T383838AppTheme { ... }. The theme is in T383838core:ui.

Reference image diff on CI but not locally: Reference images should be generated on CI (Ubuntu) or with an identical JDK version. Minor font rendering differences between macOS and Linux are absorbed by the T383838imageDifferenceThreshold (0.05%).

T383838@PreviewTest not resolving: Ensure T383838screenshotTestImplementation(libs.screenshot.validation.api) is in T383838screenshot-tests/build.gradle.kts.

File Naming Conventions

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ File type β”‚ Location β”‚ Convention β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Preview composable β”‚ T383838{module}/src/commonMai… β”‚ Group related previews in T383838*Previews.kt files β”‚
β”‚ Screenshot test wrapper β”‚ T383838screenshot-tests/src/s… β”‚ One file per source module β”‚
β”‚ Reference image β”‚ T383838screenshot-tests/src/s… β”‚ Auto-generated names (do not rename) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Served by rngit 1.5.0 - Generated in 0.05s